<template>
  <div class="content-layout-body">
    <div class="search__example--wrap">
      <base-search
        :title="t('keys.copyToMeList')"
        :schema="getccToMeSearchData()"
        :expand="true"
        @search-submit="searchSubmit"
        @reset-submit="resetSubmit"
        v-permission="['home.approvalCenter.ccToMeList.see']"
      />
    </div>

    <base-table
      ref="tableRefCom"
      v-loading="loading"
      border
      :selection="false"
      reserveSelection
      :row-style="{ cursor: 'pointer' }"
      row-key="id"
      rowKey="id"
      :columns="getccToMeList()"
      :data="tableData"
      :pagination="{
        currentPage: defaultParams.page,
        total: total,
        onSizeChange: handleSizeChange,
        onCurrentChange: handleCurrentChange
      }"
      v-permission="['home.approvalCenter.ccToMeList.see']"
    >
      <template #ticketCode="scope">
        <el-button type="info" link @click.stop="goToBeApprovedDetails(scope.row)">{{ scope.row.ticketCode }}</el-button>
      </template>
    </base-table>
  </div>
</template>

<script setup>
import { ref, onActivated } from 'vue'
import { useRouter } from 'vue-router'
import { useBasicData } from './hooks/useBasicData'
import { getccToMeList } from './tableColumn'
import { getccToMeSearchData } from './hooks/useSearchData'
import { ccMyListApi } from 'api/personalCenter'

// import ZcbSearch from 'components/zcb-search'
// import BasicTable from 'components/table/basicTable.vue'
import { useI18n } from 'vue-i18n'
const { t } = useI18n() // 中英文
const router = useRouter()
const {
  tableRefCom,
  defaultParams,
  tableData,
  loading,
  total,
  rowData,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  onRowClick,
  getList,
  searchSubmit,
  resetSubmit
} = useBasicData({
  listFun: ccMyListApi
})

// 每次都执行
onActivated(() => {
  getList()
})

const goToBeApprovedDetails = (row) => {
  router.push({
    name: 'ccToMeListDetails',
    query: {
      instanceId: row.processInstanceId,
      ticketCode: row.ticketCode,
      ticketName: row.ticketName,
      sourceType: 'ccToMeList',
      source: 'preview'
    }
  })
}
</script>
